from opencv import cv
from opencv import highgui
DEV = 0

if __name__ == '__main__':
    
    
    highgui.cvNamedWindow('CleanInput',highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvMoveWindow('CleanInput',10,10)
    
    highgui.cvNamedWindow('Canny',highgui.CV_WINDOW_AUTOSIZE)
    highgui.cvMoveWindow('Canny',650,10)
    
    capture = highgui.cvCreateCameraCapture(DEV)
    key = ''
    while key != 'q':
            frame_origin = highgui.cvQueryFrame(capture) 
            frame_bw = cv.cvCreateImage(cv.cvGetSize(frame_origin),cv.IPL_DEPTH_8U,1) 
            frame_canny = cv.cvCreateImage(cv.cvGetSize(frame_origin),cv.IPL_DEPTH_8U,1)
            cv.cvCvtColor(frame_origin,frame_bw,cv.CV_RGB2GRAY) 
            cv.cvCanny(frame_bw,frame_canny,500,100,3)
            highgui.cvShowImage('Canny',frame_canny) 
          
            storage = cv.cvCreateMemStorage(0)
            count,seq = cv.cvFindContours(frame_canny,storage)
            i = range(count)
            for a in i:
                cv.cvDrawLine(frame_origin,seq[a-1],seq[a],255)
                
            
            
            
            highgui.cvShowImage('CleanInput',frame_origin)
            
            key = highgui.cvWaitKey(1)
            
            

